#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def get_fund_data(code, pagen=10):
    # read table of data from url
    for p in range(1, pagen+1):
        url = r'http://fund.eastmoney.com/f10/F10DataApi.aspx?type=lsjz'
        resp = requests.post(url, data={'code':code, 'per':20, 'page':p})
        soup = bs4.BeautifulSoup(resp.content, 'lxml')
        table= soup.table
        if p == 1:
            data = table2frame(table)
        else:
            try:
                data = pd.concat([data, table2frame(table)])
            except:
                break
    url = r'http://fund.eastmoney.com/f10/jjjz_%s.html'%code
    resp = requests.get(url)
    soup = bs4.BeautifulSoup(resp.content, 'lxml')
    title = soup.title
    rx = re.compile(r'.*(?=\(%s\))'%code)
    m = rx.match(title.string)
    name = m[0]
    return data, name
